def is_prime(num):
    if num == 1:
        return False
    test = True
    kok = num - 1
    while kok > 1:
        if not num % kok:
            test = False
            break
        kok -= 1
    return test

number = input()
result = []
for i in range(len (number)):
    for kok in range(i + 1, len(number) + 1):
        num = int(number[i:kok])
        if is_prime(num):
            result += [num]
print(max(result) if result else 0)
        